package com.hexb.arithmetic.astart
{
	public class AStartUtils
	{
		
		/*
		*从起点，沿着产生的路径，移动到网格上指定方格的相对移动耗费
		*@parameter parentPoint 开始的点，如果是原始起点，则这点的G值为0
		*@parameter targetPoint 要移动到的点
		**/
		public static function countGvalue(parentPoint:APoint,targetPoint:APoint):int{
			//如果在相邻的同一行，列上
			if(Math.abs(parentPoint.x - targetPoint.x) + Math.abs(parentPoint.y - targetPoint.y)==1){
				return 10 ;
			}
			//如果在对角线位置
			if(Math.abs(parentPoint.x - targetPoint.x) + Math.abs(parentPoint.y - targetPoint.y)==2){
				return 14 ;
			}
			return 0 ;
		}
		
		/*
		*从网格上那个方格移动到终点B的预估移动耗费H 
		**/
		public static function countHValue(startPoint:APoint,endPoint:APoint):int{
			var xDiff:int = Math.abs(startPoint.x - endPoint.x) ;
			var yDiff:int = Math.abs(startPoint.y - endPoint.y) ;	
//			return (xDiff + yDiff) * 2 ;
			return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
		}
		
		public function AStartUtils()
		{
		}
	}
}